package org.example.infrastructure.repository.orm.database;

import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.example.domain.model.entity.url.UrlShortener;
import org.example.domain.model.entity.url.req.RecycleBinPageReq;
import org.example.domain.repository.RecycleBinServiceRepository;
import org.example.infrastructure.persistence.orm.RecycleBinMapper;
import org.springframework.stereotype.Component;

import java.util.List;

@Component
@Slf4j
@RequiredArgsConstructor
public class MybatisRecycleBinServiceRepository implements RecycleBinServiceRepository {
    private final RecycleBinMapper recycleBinMapper;


    @Override
    public PageInfo<UrlShortener> recycleBinPage(RecycleBinPageReq recycleBinPageReq, List<String> gitList) {
        PageHelper.startPage(recycleBinPageReq.getPageNum(), recycleBinPageReq.getPageSize());
        List<UrlShortener> urlShorteners = recycleBinMapper.selectByPage(gitList);
        return new PageInfo(urlShorteners);
    }

    @Override
    public void saveRecycleBin(String gid, String fullShortUrl) {
        recycleBinMapper.saveRecycleBin(gid, fullShortUrl);
    }

    @Override
    public void recoverRecycleBin(String gid, String fullShortUrl) {
        recycleBinMapper.recoverRecycleBin(gid, fullShortUrl);
    }

    @Override
    public void removeRecycleBin(String gid, String fullShortUrl) {
        recycleBinMapper.removeRecycleBin(gid, fullShortUrl);
    }
}
